<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>echarts地图</title>
    <script src="../js/data.js"></script>
    <script src="../js/vue2.js"></script>
    <script src="../js/echarts.min.js"></script>
    <script src="../js/jquery.min.js"></script>
</head>

<body>
<div class="viewport" id="home">
    <div class="echarts" id="echarts"></div>
    <div class="list">
        <div class="listItem">
            <div class="topLeftbg"></div>
            <div class="bottomRight"></div>
            <p>测试</p>
            <span>重点发展产业：</span>
            <div class="desc">123</div>
        </div>
    </div>
</div>
</body>
<script>
    function GetRandomNum(Min, Max) {
        var Range = Max - Min;
        var Rand = Math.random();
        return (Min + Math.round(Rand * Range));
    }

    // 获取数据
    function getData() {
        $.get('../js/data.json', function (data) {
            getEcharts(data)
        });
    }

    // 渲染echarts
    function getEcharts(data) {
        var chartDom = document.getElementById('echarts');
        var myChart = echarts.init(chartDom);
        var nameMap = '地图数据';
        var geoCoordMap = {};
        echarts.registerMap(nameMap, data);
        var labelData = []
        var mapFeatures = echarts.getMap(nameMap).geoJson.features;
        mapFeatures.forEach(function (v, index) {
            console.log(mapFeatures[(mapFeatures.length - 1) - index])
            if (index < 3) {
                labelData.push({
                        name: v.properties.name, value: 1,
                        coords: [v.properties.center,
                            [
                                mapFeatures[(mapFeatures.length - 2) - index].properties.center[0],
                                mapFeatures[(mapFeatures.length - 1) - index].properties.center[1],
                            ]
                        ]
                    },
                );
            }
            var name = v.properties.name;
            geoCoordMap[name] = v.properties.center;
        });
        var option = {
            //图例
            geo: {
                map: nameMap,
                zoom: 1,
                label: {
                    normal: {
                        show: false,
                        color: '#000000'
                    },
                    emphasis: {
                        show: false,
                        color: '#292929'
                    }
                },
                roam: false,
                itemStyle: {
                    normal: {
                        areaColor: '#00338F',
                        borderColor: '#0094D6',
                        borderWidth: 0.5,
                        label: {
                            show: false,
                        }
                    },
                    emphasis: {
                        areaColor: '#FFBB07',
                        borderColor: '#0094D6',
                        areaStyle: '#FFBB07',
                        label: {
                            show: false,
                        }
                    }
                },
            },
            series: [
                {
                    type: 'lines',
                    data: labelData,
                    symbolSize: 5,
                    symbol: 'circle',
                    color: 'red',
                    label: {
                        show: true,
                        padding: [15, 15],
                        color: '#fff',
                        areaColor: 'red',
                        borderRadius: 6,
                        formatter: '{b}'
                    },
                    lineStyle: {
                        type: 'solid',
                        opacity: 1,
                        color: '#52E5EF'
                    }
                }
            ]
        }
        myChart.resize()
        myChart.setOption(option)
    }

    if (window.location.origin == 'file://') {
        setTimeout(() => {
            getEcharts(gdMap)
        }, 100)
    } else {
        getData()
    }
</script>
</html>
<style>
    html, body {
        padding: 0;
        margin: 0;
    }

    #home {
        width: 100%;
        height: 100%;
        background: #0d1551;
        position: fixed;
    }

    .echarts {
        width: 100%;
        height: 100%;
        background: #0d1551;
        position: fixed;
    }

    .info {
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 10;
        color: red;
    }

    .links {
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 10;

    }

    .links a {
        text-decoration: none;
        color: #fff;
    }
</style>
